﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Model;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace DAL
{
   public class users_dal
    {
        /// <summary>
        /// 链接数据库
        /// </summary>
        Database db = DatabaseFactory.CreateDatabase("constring");
        /// <summary>
        /// 前台用户登录用户登录
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Pwd"></param>
        /// <returns></returns>
        public List<users> Login(string Login_Name, string Login_Pwd)
        {
            DataSet ds = db.ExecuteDataSet(CommandType.Text, "select Login_Id,Login_Name,Login_Pwd,Login_Nickname from Users where Login_Name='" + Login_Name + "' and Login_Pwd='" + Login_Pwd + "'");
            List<users> list = new List<users>();
            DataTable dt = ds.Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                users u = new users();
                u.Login_Id = Convert.ToInt32(dr["Login_Id"]);
                u.Login_Name = dr["Login_Name"].ToString();
                u.Login_Pwd = dr["Login_Pwd"].ToString();
                u.Login_Nickname = dr["Login_Nickname"].ToString();
                list.Add(u);
            }
            return list;
        }
       /// <summary>
       /// 获取所有用户
       /// </summary>
       /// <returns></returns>
        public List<users> GetUsers()
        {
            DataSet ds = db.ExecuteDataSet(CommandType.Text, "select Login_Id,Login_Name from users");
            List<users> list = new List<users>();
            DataTable dt = ds.Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                users u = new users();
                u.Login_Id = Convert.ToInt32(dr["Login_Id"]);
                u.Login_Name = dr["Login_Name"].ToString();
                list.Add(u);
            }
            return list;
        }
    }
}
